﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WMS_MAV;
using System.ComponentModel.DataAnnotations;
//using XuanKeZz.Application.HTTP;

namespace WMS_MAV.Controllers
{
    public class DeviceController : Controller
    {
        private readonly IConfiguration _configuration;

        public DeviceController(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 设备
        /// </summary>
        /// <returns></returns>
        public IActionResult Device()
        {
            return View();
        }
        /// <summary>
        /// 设备显示
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> DeviceDo(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "deviceRead/api/Device/DeviceShow";
            var datas = JsonConvert.SerializeObject(model);
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 设备单删
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> IsDelDo(string model,string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "device/api/Device/DeviceDelete";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 设备添加
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult>  DeviceAddDo(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "device/api/Device/DeviceAdd";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 设备反填
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> DeviceFanDo(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "device/api/Device/DeviceFan";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 设备修改
        /// </summary>
        /// <param name="models"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> DeviceupdateDo(string models, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "device/api/Device/DeviceUpdate";
            var response = await httpClientWrapper.PostAsync(url, models);
            return Json(response);
        }
        /// <summary>
        /// 设备批量删除
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> DeviceIsdelAllDo(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "device/api/Device/DeviceDeleteAll";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
    }
}
